package com.kws.merchant.controller;


import com.kws.common.config.constant.MinioCommonBucket;
import com.kws.merchant.domain.MerchantCase;
import com.kws.merchant.domain.po.CheckVo;
import com.kws.merchant.domain.po.MerchantCasePo;
import com.kws.merchant.service.MerchantCaseService;
import com.kws.merchant.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 商家-案例(MerchantCase)表控制层
 *
 * @author yxy
 * @since 2024-11-01 09:43:22
 */
@RestController
@Api(tags = "商家-案例(MerchantCase)")
@RequestMapping("merchantCase")
public class MerchantCaseController {

    @Value("${minio.ENDPOINT}")
    private String minioUrl;
    /**
     * 服务对象
     */
    @Resource
    private MerchantCaseService merchantCaseService;
 
    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<MerchantCase>> pageList(@RequestBody MerchantCasePo merchantCasePo){
        return R.ok(merchantCaseService.pageList(merchantCasePo));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<MerchantCase> detailById(@PathVariable Long id) {
        MerchantCase merchantCase = merchantCaseService.getById(id);
        merchantCase.setFile(FileUtil.fixFileName()+merchantCase.getFile());
        return R.ok();
    }


    @PostMapping("/addMerchantCase")
    @ApiOperation("商家案例新增")
    public R addMerchantCase(@RequestBody MerchantCase merchantAwards){
        return R.ok(merchantCaseService.addMerchantCase(merchantAwards));
    }
    @PostMapping("/update")
    @ApiOperation(value = "修改数据")
    public R update(@RequestBody MerchantCase merchantCase) {
        merchantCase.setFile(FileUtil.subFileName(merchantCase.getFile()));
        return R.ok(merchantCaseService.updateById(merchantCase));
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除数据")
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(merchantCaseService.removeByIds(idList));
    }

    @ApiOperation("商家案例审核")
    @PostMapping("merchantCaseCheck")
    public R merchantCaseCheck(@RequestBody CheckVo checkVo){
        return R.ok(merchantCaseService.merchantCaseCheck(checkVo));
    }
}
